package com.trkj.focusonzhuzhou.user.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import com.trkj.focusonzhuzhou.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CityActivityAdapter extends BaseAdapter {

	private List<CityActivity> list = new ArrayList<CityActivity>();
	private Context context;
	
	public CityActivityAdapter() {
		super();
	}

	public CityActivityAdapter(List<CityActivity> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View converView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		
		if(converView == null){
			
			viewHolder = new ViewHolder();
			converView = LayoutInflater.from(context).inflate(R.layout.activity_items, null);
			
			viewHolder.tvTitle = (TextView) converView.findViewById(R.id.tv_activity_title);
			viewHolder.tvContent = (TextView) converView.findViewById(R.id.tv_activity_content);
			viewHolder.tvDate = (TextView) converView.findViewById(R.id.tv_end_date);
			viewHolder.tvNumber = (TextView) converView.findViewById(R.id.tv_involved_number);
			
			CityActivity activity = list.get(position);
			
			viewHolder.tvTitle.setText(activity.getActivityTitle());
			viewHolder.tvContent.setText(activity.getActicityContent());
			viewHolder.tvDate.setText(df.format(activity.getEndDate()));
			viewHolder.tvNumber.setText(activity.getNumber() + "");
			
			converView.setTag(viewHolder);
			
		}else{
			viewHolder = (ViewHolder) converView.getTag();
		}
		
		return converView;
	}

	private class ViewHolder{
		
		private TextView tvTitle;
		private TextView tvContent;
		private TextView tvDate;
		private TextView tvNumber;
	}
}
